<? if($cal_only!='yes'): ?>
<?php echo $this->load->view('meta'); ?>
<script type="text/javascript">
function events(id,day){
	$.ajax({
	  url: '<?=base_url()?>calendar/event/' + id +'/',
	  cache: true,
	  success: function(html){
	    if(html!=""){
			sidebar(id);
			$('#replace_event').html(html).css("display","block");
			$('html,body').animate({scrollTop:140}, 'slow');
			$('.containerr').find('div:first').removeClass('selected_date').addClass('date');
			$('#'+day).removeClass('date').addClass('selected_date');
			$('#map').each(function(){
		    	var url = $(this).attr('href') + '?&TB_iframe=trueKeepThis=true&height=325&width=500';
			    $(this).attr('href', url);
		     });
		} else{
			hideEvent();
		}
	  }
	});
}
function sidebar(id){
	$.ajax({
	  url: '<?=base_url()?>calendar/sidebar/' + id +'/',
	  cache: true,
	  success: function(html){
	    $('#sidebar').html(html).css("display","block");
		$('#deleteEvent').each(function(){
			var url = $(this).attr('href') + '?height=100&width=400';
			$(this).attr('href', url);
	 	});

	  }
	});
}
function calendardate(m,y){
	$.ajax({
	  url: '<?=base_url()?>calendar/full/' + m + '/' + y + '/cal_only/',
	  cache: true,
	  success: function(html){
	    $('#full_calendar').html(html);
	  }
	});
}
function hideEvent(){
	 $('#replace_event').css("display","none");
	$('html,body').animate({scrollTop:0}, 'slow');
	$('.containerr').find('div:first').removeClass('selected_date').addClass('date');
	sidebar('none');
}
function thickboxDone() {
	tb_remove();
	window.location.reload();
}
</script>
<? if(!isset($loggedin)) : ?>
<style type="text/css">
.full{
       width: 100%;
}
</style>
<? endif; ?>
<title>xa-ncsu | calendar</title>
<?php echo $this->load->view('header'); ?>
<h2>calendar</h2>
<div id="full_calendar">
<? endif ?>
<? if(isset($event) && $event!=null && $event!='no') : ?>
<div id="replace_event" style="display:block;">
		<?= $this->load->view('calendar/eventView'); ?>
		<script type="text/javascript">
		sidebar(<?=$id?>);
		</script>
<? else : ?>
<div id="replace_event">
<? endif; ?>
</div>
<table class="full" <?= (!isset($loggedin)) ? 'style="width:100%;"' : '' ?>>
	<tr>
		<td colspan='2'><a href='javascript:;' onClick="calendardate(<?=date("n",$date)?>, <?=date("Y",strtotime("-1 year",$date))?>)"><span style="font-size:10px">Previous Year</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:;' onClick="calendardate(<?=date("n",strtotime("-1 month",$date))?>, <?=date("Y",strtotime("-1 month",$date))?>)"><span style="font-size:10px">Previous Month</span></a></td><td colspan='3'><span style="font-size:18px;"><?=date("F Y",$date)?></span></td>
		
		<td colspan='2'><a href='javascript:;' onClick="calendardate(<?=date("n",strtotime("+1 month",$date))?>, <?=date("Y",strtotime("+1 month",$date))?>)"><span style="font-size:10px">Next Month</span></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:;' onClick="calendardate(<?=date("n",$date)?>, <?=date("Y",strtotime("+1 year",$date))?>)"><span style="font-size:10px">Next Year</span></a></td</tr>
	<tr>
		<th>Sunday</th>
		<th>Monday</th>
		<th>Tuesday</th>
		<th>Wednesday</th>
		<th>Thursday</th>
		<th>Friday</th>
		<th>Saturday</th>
	</tr>
	<? foreach ($dates as $day): ?>
	<tr>
	<? for ($i=0;$i<7;$i++): ?>
		<td><div class='containerr'><div id="<?=$day[$i]?>" class='date'><?=$day[$i]?></div>
		<? if(isset($events)): ?>
			<? if(array_key_exists($day[$i],$events)): ?>
					<? foreach($events[$day[$i]] as $current): ?>
						<? $a = (strtotime("$current[end]") - strtotime("$current[start]"))/(60*60*24);?>
						<? if($a<1):?>
			<a href='javascript:;' onClick="events(<?=$current['id']?>,<?=$day[$i]?>);"><div class='event'><?=date("g:ia",strtotime("$current[start]"))?> <?=$current['name']?></div></a>
						<? elseif($a==1): ?>
			<a href='javascript:;' onClick="events(<?=$current['id']?>,<?=$day[$i]?>);"><div class='event_all_day'><?=date("g:ia",strtotime("$current[start]"))?> <?=$current['name']?></div></a>
						<? else :?>
							<? if($day[$i]==date("j",strtotime("$current[start]"))): ?>
			<a href='javascript:;' onClick="events(<?=$current['id']?>,<?=$day[$i]?>);"><div class='event_spanning' style="padding:0px;"><?=date("g:ia",strtotime("$current[start]"))?> <?=$current['name']?></div></a>
							<? else: ?>
			<a href='javascript:;' onClick="events(<?=$current['id']?>,<?=$day[$i]?>);"><div class='event_spanning' style="padding:0px;"><?=$current['name']?></div></a>
							<? endif;?>
						<? endif; ?>
					<? endforeach; ?>
			</div></td>
					
				
				<? else: ?>
			</div></td>
				<? endif; ?>
			</div></td>
			<? else: ?>
			</div></td>
			<? endif; ?>
			
			<? endfor; ?>
		</tr>
			<? endforeach; ?>

</table>
</div>
<? if($cal_only!='yes'): ?>
<?=$this->load->view('footer');?>
<? endif ?>